/**
 * 需求:
 * 读取 resource/1.html 内容
 */
const fs = require('fs');

//原生方式
// fs.readFile('./resource/1.html', (err, data) => {
//   if(err) throw err;
//   console.log(data.toString());
// });

// Promise
let p = new Promise((resolve, reject) => {
  //异步任务
  fs.readFile('./resource/1.htm', (err, data) => {
    //失败
    if(err){
      reject(err);
    }else{
      //成功
      resolve(data);
    }
  });
});

p.then(value => {
  console.log(value.toString());
}, reason => {
  // console.log(reason);
  console.log('当前的错误编号为' + reason.errno);
})

